#pragma once

#include "glut.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include<time.h>
#include <iostream>
#include "text.h"
#include "data.h"
using namespace std;
void DrawCube(float x, float y, float z, GLuint _bitmap)
{
	//glColor3f(1, 1, 1);
	glPushMatrix();
	glScalef(x, y, z);//不同的六面体进行不同的缩放
	//6面体
	glEnable(GL_TEXTURE_2D);//---------------------------启动纹理，不改的话之后2D都沿用这个纹理
	//qian	
	glBindTexture(GL_TEXTURE_2D, _bitmap);//---------对纹理进行绑定 不能放在glbegin() 和glend()之前 ，否则多次加载无限
	glBegin(GL_QUADS);

	//3.在六面体用户坐标系画一个面
	//六面体几何中心是六面体用户坐标系的0,0,0
	glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, -1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(0.0, 1.0); glVertex3f(1.0f, -1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 1.0); glVertex3f(1.0f, 1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 0.0); glVertex3f(-1.0f, 1.0f, 1.0f);//纹理坐标映射
	glEnd();
	//hou
	//glBindTexture(GL_TEXTURE_2D, g_bitmap[1]);//---------对纹理进行绑定 不能放在glbegin() 和glend()之前 ，否则多次加载无限
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, -1.0f, -1.0f);//纹理坐标映射
	glTexCoord2f(0.0, 1.0); glVertex3f(1.0f, -1.0f, -1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 1.0); glVertex3f(1.0f, 1.0f, -1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 0.0); glVertex3f(-1.0f, 1.0f, -1.0f);//纹理坐标映射
	glEnd();
	//zuo
	//glBindTexture(GL_TEXTURE_2D, g_bitmap[2]);//---------对纹理进行绑定 不能放在glbegin() 和glend()之前 ，否则多次加载无限
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, -1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(0.0, 1.0); glVertex3f(-1.0f, 1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 1.0); glVertex3f(-1.0f, 1.0f, -1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 0.0); glVertex3f(-1.0f, -1.0f, -1.0f);//纹理坐标映射
	glEnd();
	//you
	//glBindTexture(GL_TEXTURE_2D, g_bitmap[3]);//---------对纹理进行绑定 不能放在glbegin() 和glend()之前 ，否则多次加载无限
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex3f(1.0f, -1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(0.0, 1.0); glVertex3f(1.0f, 1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 1.0); glVertex3f(1.0f, 1.0f, -1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 0.0); glVertex3f(1.0f, -1.0f, -1.0f);//纹理坐标映射
	glEnd();
	//shang
	//glBindTexture(GL_TEXTURE_2D, g_bitmap[4]);//---------对纹理进行绑定 不能放在glbegin() 和glend()之前 ，否则多次加载无限
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, 1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(0.0, 1.0); glVertex3f(1.0f, 1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 1.0); glVertex3f(1.0f, 1.0f, -1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 0.0); glVertex3f(-1.0f, 1.0f, -1.0f);//纹理坐标映射
	glEnd();
	//xia
	//glBindTexture(GL_TEXTURE_2D, g_bitmap[5]);//---------对纹理进行绑定 不能放在glbegin() 和glend()之前 ，否则多次加载无限
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, -1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(0.0, 1.0); glVertex3f(1.0f, -1.0f, 1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 1.0); glVertex3f(1.0f, -1.0f, -1.0f);//纹理坐标映射
	glTexCoord2f(1.0, 0.0); glVertex3f(-1.0f, -1.0f, -1.0f);//纹理坐标映射
	glEnd();

	glPopMatrix();
	glDisable(GL_TEXTURE_2D);
}
void DrawDesk()
{
	//233 216 133
	glPushMatrix();

	float ambientlight1[] = { 116.0 / 250.0,165.0 / 250.0 ,182.0 / 250.0,1.0f };

	//float ambientlight1[] = { 0.0f, 0.0f, 0.2f, 1.0f };

	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight1);
	//桌子面
	glPushMatrix();

	//2.桌子用户坐标系平移，比如这个桌子面要高一点，
	//整个桌子中心在桌子用户坐标系的（0，0，0）
	glTranslatef(0, 0.71, 0);

	//在桌子用户坐标系的（0,0.71,0）位置画一个1,0.1,1比例的六面体作为桌子面
	DrawCube(1, 0.1, 1, g_bitmap[0]);
	//DrawCube(1, 0.1, 1, 0);
	glPopMatrix();

	float ambientlight2[] = { 0.1, 0.1, 0.1,1.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight2);
	//桌子腿1
	glPushMatrix();
	glTranslatef(0.8, 0.0, 0.8);
	DrawCube(0.1, 0.8, 0.1, g_bitmap[0]);
	//DrawCube(0.1, 0.8, 0.1, 0);
	glPopMatrix();
	//桌子腿2
	glPushMatrix();
	glTranslatef(-0.8, 0.0, 0.8);
	DrawCube(0.1, 0.8, 0.1, g_bitmap[0]);
	//DrawCube(0.1, 0.8, 0.1, 0);
	glPopMatrix();
	//桌子腿3
	glPushMatrix();
	glTranslatef(-0.8, 0.0, -0.8);
	DrawCube(0.1, 0.8, 0.1, g_bitmap[0]);
	//DrawCube(0.1, 0.8, 0.1, 0);
	glPopMatrix();
	//桌子腿4
	glPushMatrix();
	glTranslatef(0.8, 0.0, -0.8);
	DrawCube(0.1, 0.8, 0.1, g_bitmap[0]);
	//DrawCube(0.1, 0.8, 0.1, 0);
	glPopMatrix();

	glPopMatrix();
}


void DrawHouse()
{
	//229 118 63
	glColor3f(1, 1, 1);
	//地面
	float ambientlight0[] = { 0.8, 0.8, 0.8,1.0f };//这里处理的暗一点

	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight0);
	glPushMatrix();
	glTranslatef(0, -10, 0);
	DrawCube(20, 0.1, 10, g_bitmap[0]);
	glPopMatrix();

	//glColor3f(0.4, 0.4, 0.4);
	float ambientlight1[] = { 0.9, 0.9, 0.9,1.0f };//这里处理的暗一点

	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight1);
	//屋顶
	glPushMatrix();
	//glColor3f(0.4, 0.4, 0.4);
	glColor3f(1, 1, 1);

	glTranslatef(0, 10, 0);
	DrawCube(20, 0.1, 10, g_bitmap[4]);
	glPopMatrix();

	//后墙
	glColor3f(0.8, 0.8, 0.8);
	float ambientlight2[] = { 1.3, 1.3, 1.3,1.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight2);
	glPushMatrix();
	glColor3f(0.8, 0.8, 0.8);
	glTranslatef(0, 0, -10);
	DrawCube(20, 10, 0.1, g_bitmap[4]);
	glPopMatrix();

	//左墙
	glColor3f(229.0 / 250.0, 118.0 / 250.0, 63.0 / 250.0);
	float ambientlight3[] = { 229.0 / 250.0, 118.0 / 250.0, 63.0 / 250.0,1.0f };

	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight2);
	glPushMatrix();
	glColor3f(0.7, 0.7, 0.7);
	glTranslatef(-20, 0, -0);
	DrawCube(0.1, 10, 10, g_bitmap[4]);
	glPopMatrix();

	//右墙
	glPushMatrix();
	glColor3f(0.7, 0.7, 0.7);
	glTranslatef(20, 0, -0);
	DrawCube(0.1, 10, 10, g_bitmap[4]);
	glPopMatrix();
}

void Cylinder(float r, float h)
{
	glBegin(GL_QUAD_STRIP);//连续填充四边形串
	int i = 0;
	for (i = 0; i <= 390; i += 15)
	{
		float p = i * 3.14 / 180;
		glVertex3f(r*sin(p), r*cos(p), h / 2.0f);
		glVertex3f(r*sin(p), r*cos(p), -h / 2.0f);
	}
	glEnd();
	//Circle();
	//glTranslatef(0, 0, 1);
	//Circle();
}

void DrawComputer()
{

	//底部
	glPushMatrix();
	glColor3f(0.1, 0.1, 0.1);
	float ambientlight1[] = { 0.1f,0.1f,0.1f,1.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight1);
	glTranslatef(0, -0.1, 0);
	DrawCube(1.2, 0.05, 0.7, 0);
	glPopMatrix();

	//屏幕
	glColor3f(1.1, 1.1, 1.1);
	float ambientlight2[] = { 1.1, 1.1, 1.1,1.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight2);

	glPushMatrix();
	glTranslatef(-0.1, 0.4, -1.6);
	glRotatef(45, 1, 0, 0);
	DrawCube(1.2, 0.05, 0.9, g_bitmap[1]);
	glPopMatrix();
}
void DrawLight()
{//
	glColor3f(1.0, 1.0, 1.0);
	float ambientlight3[] = { 229.0 / 250.0, 63.0 / 250.0, 118.0 / 250.0,1.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight3);
	glPushMatrix();
	glTranslatef(0.0, 0, -0.8);
	glRotatef(180, 1, 0, 0);
	if (model == 2)
		glutSolidCone(2.0, 1.2, 50, 50);
	else
		glutWireCone(2.0, 1.2, 50, 50);

	glPopMatrix();


	float ambientlight[] = { 0.2,0.2,0.2,1.0 };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight);
	glPushMatrix();
	glTranslatef(0.0, 0, -3.5);
	Cylinder(0.15, 4.5);
	glPopMatrix();
}
void DrawDrawer()
{
	//240 183 93

	glPushMatrix();
	glRotatef(90, 0, 0, 1);
	glTranslatef(0, 0.5, 0);
	glScalef(1.0, 2.0, 1.0);
	float ambientlight1[] = { 0.1, 0.1, 0.1,1.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight1);
	glPushMatrix();
	glTranslatef(-0.3, 0.01, 0.4);
	DrawCube(0.02, 0.1, 0.1, g_bitmap[0]);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0.3, 0.01, 0.4);
	DrawCube(0.02, 0.1, 0.1, g_bitmap[0]);
	glPopMatrix();



	float ambientlight[] = { 240.0 / 250.0, 183.0 / 250.0, 93.0 / 250.0,1.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight);
	glPushMatrix();
	glTranslatef(-0.305, 0.005, 0);
	DrawCube(0.3, 0.4, 0.4, g_bitmap[3]);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(0.305, 0.005, 0);
	DrawCube(0.3, 0.4, 0.4, g_bitmap[3]);
	glPopMatrix();




	glPopMatrix();

}
void DrawLightGan()
{
	//glColor3f(229.0 / 250.0, 118.0 / 250.0, 63.0 / 250.0);


	float ambientlight[] = { 0.2,0.2,0.2,1.0 };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight);
	glPushMatrix();
	glTranslatef(0.0, 0, -5.0);
	//glRotatef(180, 1, 0, 0);
	Cylinder(0.35, 10.0);
	glPopMatrix();


	float ambientlight3[] = { 229.0 / 250.0, 120.0 / 250.0, 80.0 / 250.0,1.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight3);
	glPushMatrix();
	glTranslatef(0.0, 0.0, 0.0);
	Cylinder(2.5, 2.5);
	glPopMatrix();
}

//xyz是平移
void DrawBox(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h, GLfloat d)
{
	glPushMatrix();
	glTranslatef(x, y, z);//平移
	glBegin(GL_QUADS);
	// 前表面
	glNormal3f(0.0f, 0.0f, 1.0f);
	glTexCoord2i(0, 0); glVertex3f(-w, -h, d);
	glTexCoord2i(1, 0); glVertex3f(w, -h, d);
	glTexCoord2i(1, 1); glVertex3f(w, h, d);
	glTexCoord2i(0, 1); glVertex3f(-w, h, d);
	// 后表面
	glNormal3f(0.0f, 0.0f, -1.0f);
	glTexCoord2i(1, 0); glVertex3f(-w, -h, -d);
	glTexCoord2i(1, 1); glVertex3f(-w, h, -d);
	glTexCoord2i(0, 1); glVertex3f(w, h, -d);
	glTexCoord2i(0, 0); glVertex3f(w, -h, -d);
	// 上表面
	glNormal3f(0.0f, 1.0f, 0.0f);
	glTexCoord2i(0, 1); glVertex3f(-w, h, -d);
	glTexCoord2i(0, 0); glVertex3f(-w, h, d);
	glTexCoord2i(1, 0); glVertex3f(w, h, d);
	glTexCoord2i(1, 1); glVertex3f(w, h, -d);
	// 下表面
	glNormal3f(0.0f, -1.0f, 0.0f);
	glTexCoord2i(1, 1); glVertex3f(-w, -h, -d);
	glTexCoord2i(0, 1); glVertex3f(w, -h, -d);
	glTexCoord2i(0, 0); glVertex3f(w, -h, d);
	glTexCoord2i(1, 0); glVertex3f(-w, -h, d);
	// 右侧面
	glNormal3f(1.0f, 0.0f, 0.0f);
	glTexCoord2i(1, 0); glVertex3f(w, -h, -d);
	glTexCoord2i(1, 1); glVertex3f(w, h, -d);
	glTexCoord2i(0, 1); glVertex3f(w, h, d);
	glTexCoord2i(0, 0); glVertex3f(w, -h, d);
	// 左侧面
	glNormal3f(-1.0f, 0.0f, 0.0f);
	glTexCoord2i(0, 0); glVertex3f(-w, -h, -d);
	glTexCoord2i(1, 0); glVertex3f(-w, -h, d);
	glTexCoord2i(1, 1); glVertex3f(-w, h, d);
	glTexCoord2i(0, 1); glVertex3f(-w, h, -d);
	glEnd();
	glPopMatrix();
}
void drawBed()
{
	float ambientlight2[] = { 1.0, 1.0, 1.0,1.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, ambientlight2);
	glPushMatrix();
	//*************************床
	glEnable(GL_TEXTURE_2D);
	glScalef(0.2, 0.2, 0.15);
	glTranslatef(0, -9, 90);
	glBindTexture(GL_TEXTURE_2D, g_bitmap[3]);
	//和桌子不同，在床用户坐标系的（-57.0f  + 75, -27.0f）画一个box，长宽高是（1.0f, 12.0f, 27.0f)
	DrawBox(-57.0f + 75, -27.0f, -92.0f, 1.0f, 12.0f, 27.0f);	       //床头板	
	DrawBox(-17.0f, -33.0f, -64.0f, 40.0f, 6.0f, 1.0f);		       // 床腿2
	DrawBox(-17.0f, -33.0f, -119.0f, 40.0f, 6.0f, 1.0f);
	glBindTexture(GL_TEXTURE_2D, g_bitmap[5]);
	glColor3f(1, 1, 1);
	DrawBox(-17.0f, -28.0f, -92.0f, 40.0f, 1.0f, 27.0f);             //床板
	glPopMatrix();
}